home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 21
/
Cream of the Crop 21 (Terry Blount) (October 1996).iso
/
comm
/
msged400.zip
/
src
/
areas.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-07-24
|
16KB
|
578 lines
/*
* AREAS.C
*
* Written by jim nutt, John Dennis and released into the public domain
* by John Dennis in 1994.
*
* This file contains the routines to select one of the areas specified
* in the config files. It pops up a list with all the areas and lets
* the user choose.
*/
#include "msged.h"
#include "main.h"
#include "menu.h"
#include "keys.h"
#include "strextra.h"
#include "memextra.h"
#include "specch.h"
void areascan(void);
static char **alist;
static char **alist2;
static void BuildList(char ***lst);
static int AreaBox(char **Itms, int y1, int y2, int len, int def,
WND * hPrev, WND * hWnd, int Sel, int Norm, int indent);
int mainArea(void)
{
WND *hCurr, *hWnd;
int ret, wid, dep, i;
msgederr = 0;
wid = maxx - 1;
dep = maxy - 2;
hCurr = Wtop();
hWnd = WndOpen(0, 1, wid, dep, NBDR, 0, cm[MN_BTXT]);
WBox(0, 0, maxx - 1, maxy - 3, cm[MN_BTXT], SBDR);
WWriteStr(3, 0, cm[LS_TTXT], "EchoID");
WWriteStr(maxx - 21, 0, cm[LS_TTXT], "Msgs");
WWriteStr(maxx - 13, 0, cm[LS_TTXT], "New");
WWriteStr(maxx - 7, 0, cm[LS_TTXT], "Last");
BuildList(&alist);
ret = AreaBox(alist, 1, min(dep - 2, SW->areas), wid - 1, SW->area, hCurr,
hWnd, cm[MN_STXT], cm[MN_NTXT], 1);
for (i = 0; i < SW->areas; i++)
{
xfree(alist[i]);
}
xfree(alist);
if (ret < 0)
{
msgederr = 1;
}
WClose(hWnd);
WCurr(hCurr);
return ret;
}
static void BuildList(char ***lst)
{
int i;
AREA *a;
char line[181];
unsigned long unread, last;
*lst = xcalloc(SW->areas + 2, sizeof(char *));
for (i = 0; i < SW->areas; i++)
{
a = arealist + i;
memset(line, ' ', sizeof line);
if (a->messages || SW->scanned)
{
last = a->lastread;
if (last > a->messages)
{
last = a->messages;
}
unread = a->messages - a->lastread;
if (unread > a->messages)
{
unread = a->messages;
}
sprintf(line, "%c%-30.30s", unread ? SC14 : ' ', a->description);
line[strlen(line)] = ' ';
sprintf(line + maxx - 26, "%7lu%7lu%7lu",
a->messages, unread, last);
}
else
{
sprintf(line, " %-30.30s", a->description);
line[strlen(line)] = ' ';
sprintf(line + maxx - 21, " - - -");
}
(*lst)[i] = xstrdup(line);
}
(*lst)[i] = NULL;
}
static void SelShowItem(char *text, int y, int len, int Attr, int indent)
{
char line[256];
memset(line, ' ', 40);
strcpy(line + indent, text);
WPutsn(1, y, len, Attr, line);
}
static void SelShowPage(char **text, int top, int bot, int len, int pos,
int Attr, int indent)
{
int i, y;
y = top;
for (i = pos; text[i] != NULL; i++)
{
if (y > bot)
{
break;
}
SelShowItem(text[i], y++, len, Attr, indent);
}
if (y <= bot)
{
while (y <= bot)
{
SelShowItem(" ", y++, len, Attr, indent);
}
}
}
static void CalcDef(int max, int cur, int *top, int miny, int maxy, int *y)
{
int dif;
unused(cur);
dif = (maxy - 1) - miny;
if ((max - 1) - *top < dif && max > dif)
{
*y = maxy;
*top = (max - 1) - dif;
}
}
static int AreaBox(char **Itms, int y1, int y2, int len, int def,
WND * hPrev, WND * hWnd, int Sel, int Norm, int indent)
{
EVT e;
char find[30];
int itemCnt, Stuff, done, curY, Msg, currItem, Top, page, i;
itemCnt = 0;
Stuff = 0;
for (i = 0; Itms[i] != NULL; i++)
{
itemCnt++;
}
currItem = def;
curY = y1;
page = y2 - y1;
Top = currItem;
if (currItem + y1 < y1)
{
curY = y1 + currItem;
Top = 0;
}
else
{
if ((itemCnt - currItem) <= (y2 - y1))
{
Top -= ((y2 - y1 + 1) - (itemCnt - Top));
curY = y1 + (def - Top);
if (Top < 0)
{
Top = 0;
curY--;
}
}
}
done = 0;
SelShowPage(Itms, y1, y2, len, Top, Norm, indent);
SelShowItem(Itms[currItem], curY, len, Sel, indent);
TTClearQue(); /* clear input queue */
memset(find, '\0', sizeof find);
while (!done)
{
if (!*find)
{
WCurr(hPrev);
WClear(16, 0, maxx - 36, 0, cm[CM_NINF]);
WWriteStr(0, 0, cm[MN_NTXT], ">>Pick New Area:");
WCurr(hWnd);
}
if (!Stuff)
{
Msg = MnuGetMsg(&e, hWnd->wid);
}
else
{
e.msgtype = WM_CHAR;
Msg = Stuff;
Stuff = 0;
}
switch (e.msgtype)
{
case WM_MOUSE:
switch (Msg)
{
case RMOU_CLCK:
case MOU_RBTUP:
return -1;
case LMOU_RPT:
case MOU_LBTDN:
case LMOU_CLCK:
{
int x, y;
WndGetRel(e.x, e.y, &x, &y);
if (y >= y1 && y <= y2) /* in window */
{
Stuff = 0;
if (x >= 0 && x < len)
{
if (y == curY)
{
if (Msg == LMOU_CLCK || Msg == MOU_LBTUP)
{
return currItem;
}
else
{
continue;
}
}
SelShowItem(Itms[currItem], curY, len, Norm, indent);
if (y > curY)
{
currItem += y - curY;
}
else
{
currItem -= curY - y;
}
curY = y;
SelShowItem(Itms[currItem], curY, len, Sel, indent);
if (Msg == LMOU_CLCK || Msg == MOU_LBTUP)
{
return currItem;
}
}
}
else
{
if (Msg != LMOU_CLCK)
{
if (y < y1)
{
Stuff = Key_Up;
}
else
{
Stuff = Key_Dwn;
}
}
}
}
memset(find, '\0', sizeof find);
break;
default:
break;
}
break;
case WM_CHAR:
switch (Msg)
{
case Key_Home:
if (!currItem)
{
break;
}
SelShowItem(Itms[currItem], curY, len, Norm, indent);
currItem = 0;
Top = 0;
curY = y1;
SelShowPage(Itms, y1, y2, len, Top, Norm, indent);
SelShowItem(Itms[currItem], curY, len, Sel, indent);
memset(find, '\0', sizeof find);
break;
case Key_End:
if (curr